function checkAll(field) {
		if(!field.length) {
			if(field.checked==true) {
				field.checked=false;
			} else {
				field.checked=true;
			}
		}
		for (var i = 0; i <= field.length; i++)
			if(field[i].checked == true) {
				field[i].checked = false;
			} else {
				field[i].checked = true;
		}
	}
	/**
	 * @author: aNKIT kHAMBHATA
	 * @desc: This function is used to calculate days in month  
	 */
	function CalDay(m,y) {
        if(m==01||m==03||m==05||m==07||m==08||m==10||m==12) {
			var dmax = 31;			
			return dmax;	        
		} else if (m==04||m==06||m==09||m==11) {
			var dmax = 30;		
			return dmax;		  
		} else {
			if((y%400==0) || (y%400==0 && y%100!=0)) {
				dmax = 29;			
				return dmax;
			} else {
                  dmax = 28;				
            }
		return dmax;
		}
	}	
$(document).ready(function(){

	/**
	 * @author: aNKIT kHAMBHATA
	 * @desc: This function is used to validate form  
	 */
$("#contactform").validate({
	rules: {
	user_confirm_password: {
	equalTo: "#user_password"
		}
	}
});
	$("#contactform").validate({
        success: function(label) {
            label.addClass("valid");
        }
	});
	jQuery.validator.addMethod("specialChar", function(value, element) {
        return this.optional(element) || /^[a-zA-Z0-9\s_]+$/.test(value);
	}, "Please Enter Proper Value");
	jQuery.validator.addMethod("specialCharWoSpace", function(value, element) {
	        return this.optional(element) || /^[a-zA-Z0-9_]+$/.test(value);
	}, "");
	jQuery.validator.addMethod("mobileNum", function(value, element) {
	         return this.optional(element) || /^[+]{1}[0-9-\(\)]+$/.test(value);
	}, "");
	jQuery.validator.addMethod("latLong", function(value, element) {
	         return this.optional(element) || /^[0-9-.]+$/.test(value);
	}, "");
	jQuery.validator.addClassRules("imageValidation", {
		accept:'jpg|jpeg|png|gif'
	});
	jQuery.validator.addClassRules("protectspecialchar", {
		  required: true,
		  specialChar:true
	});
	jQuery.validator.addClassRules("videoValidation", {
	  required: true,
	  accept:'mp4'
	});
	
	jQuery.validator.addClassRules("unique", {
	  specialChar: false,
	  remote: $('.unique').attr('alt'),
	  
	  onkeyup: false 
	  
	});
	 jQuery.extend(jQuery.validator.messages, {
		remote : 'Already Exists.Please Try Another Value !',
		
	 });
	/**
	 * @author: aNKIT kHAMBHATA
	 * @desc: This function is used to check all checkbox
	 */
	
	/**
	 * @author: aNKIT kHAMBHATA
	 * @desc: This is used to generate date in listing page  
	 */
	DateGenerator=function () {
		var interval=$("#interval").attr("value");
		var date1,date2;
		var d = new Date();
		var t_date=parseInt(d.getDate());
		var t_month=parseInt(d.getMonth());
		var t_year = parseInt(d.getFullYear());
		//var t_year=parseInt(t_year);
		
		if(interval == 'today') {
			var date1 = t_month+1 +"/"+ t_date+"/"+t_year;
			var date2 = t_month+1 +"/"+ t_date+"/"+t_year;
		} else if (interval == 'yesterday') {
			var date1 = t_month+1 +"/"+ t_date+"/"+t_year;
			var date2 = t_month+1 +"/"+ (t_date-1)+"/"+t_year;
		} else if (interval == 'thismonth') {
			var month_days=CalDay(t_month+1,t_year);
			var date1 = t_month+1 +"/"+1+"/"+t_year;
			var date2 = t_month+1 +"/"+ month_days+"/"+t_year;
		} else if (interval == 'lastmonth') {
			var month_days=CalDay(t_month,t_year);
			var date1 = t_month +"/"+1+"/"+t_year;
			var date2 = t_month +"/"+ month_days+"/"+t_year;
		} else {
			var date1="";
			var date2="";
			
		}	
		document.getElementById("date2").value=date2;
		document.getElementById("date1").value=date1;
		
	}
	/**
	 * @author: aNKIT kHAMBHATA
	 * @desc: This function is used to hide message div  
	 */
	Hide=function(d){
		$("#"+d).slideUp("slow");
		return false;
	}
	/**
	 * @author: aNKIT kHAMBHATA
	 * @desc: This function is used to database active inactive and delete  
	 */
	makeActiveInactiveDelete=function (id,act,start,key) {
		if(act == 1) {
			a='Inactive';
		} else if (act == 2) {
			a='Active';
		} else if (act == 3) {
			a='Delete';
		} 
		
		var selector_checked = $("input[@id=chk]:checked").length; 
		
		//jAlert(selector_checked) ;
		if (selector_checked == 0) { 
			$('.chk_'+id).attr('checked',true);
			var answer = confirm('Are You Sure You Want To '+a+'?');
   			if (answer){
           		$('#myform').attr('action','control/activeinactivedelete_controller.php?makestatus=1&act='+a+'&start='+start+'&primarykey='+key);
				$('#myform').submit();
			} else {
				$('.chk_'+id).removeAttr('checked');
				return false;
			}
		} else { 
			$('.chk_'+id).removeAttr('checked');
			return false;
		}
	}
	/**
	 * @author: aNKIT kHAMBHATA
	 * @desc: This function is used to calculate days in month  
	 */
	multipleDelete=function(start){
		var selector_checked = $("input[@id=chk]:checked").length; 
		if(selector_checked > 0 ){
			var answer = confirm('Are You Sure You Want To Delete ?');
			if(answer){
				$('#myform').attr('action','control/activeinactivedelete_controller.php?makestatus=1&act=Delete&start='+start);
				$('#myform').submit();
			} else {
			}
		} else {
			jAlert('Please Selected Atleast One item for delete !', 'Alert Dialog');
			return false ;
		}
	}
	/**
	 * @author: aNKIT kHAMBHATA
	 * @desc: This function is used to for save and get same page but field is empty  
	 */
	saveAndNew=function (table,page,fieldname,id,act,check) {
		var ck;
		if (check==0){
			ck =0;
		} else{
			ck=1;
		}
		$('#contactform').attr('action','control/insert.php?tablename='+table+'&page='+page+'&act='+act+'&check='+ck+'&fieldname='+fieldname+'&id='+id+'&savenew=1');
		$('#contactform').submit();
	}
	MakeDelete=function (table,act,page) {
		var checked = $("input[@id=chk]:checked").length;
			if(checked >0) {
				var answer = confirm('Are You Sure You Want To '+act+'?');
				if(answer) {
					$('#myform').attr('action','control/insert.php?tablename='+table+'&page='+page+'&act='+act+'&makestatus=1');
					$('#myform').submit();
				} else {
					return false;
				}
			} else {
				jAlert("Please Select Atlease one Row for "+act+"!");
				return false;
			}
	}
	/**
	 * @author: aNKIT kHAMBHATA
	 * @desc: This function is used to generate Datapicker`  
	 */
	createDatePicker =function(id){
		$("#"+id).datepicker({
			showOn:'both',
			buttonImage: '../public/images/calendar.gif',
			buttonImageOnly: true
		});
	}
	/**
	 * @author:aNKIT kHAMBHATA
	 * @desc:This function is used to generate dropdown with ajax request
	 */	
	getDropDownUsingAjax=function(dataSet,type,place){
		$.ajax({
			type:"POST",
			url:"control/dropdown_controller.php?act=getDropDown&type="+type,
			data:{json:dataSet},
			success: function(msg){
				$("#"+place).html(msg);
				return false;
			}
		});
	}
		
}); // -- end --//
